/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = frshm_pool_free.c                                  */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/13 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "../../../src/lib/apmshm/frshm_pool.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static int g_i_shmid = 0;
extern int frshm_pool_create(char *p_file, int i_pool_size, int i_shm_size);
extern void frshm_pool_free(int i_shmid);

static void __frshm_init(void)
{
    char *p_shm_file = (char *)"shm_file";
    char arr_cmd[1024];
    
    snprintf(arr_cmd, sizeof(arr_cmd), "touch %s", p_shm_file);
    system(arr_cmd);
    
    g_i_shmid = frshm_pool_create(p_shm_file, 2, 10);
    
    return;
}

static void case1(void)
{
    
    frshm_pool_free(-1);
    
    return;
}

static void case2(void)
{
    __frshm_init();
    frshm_pool_free(g_i_shmid);
    return;
}

int add_suite_frshm_pool_free(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frcomm frshm_pool_free()", __suite_init, __suite_cleanup)) == NULL)
    return FR_FAIL;

    CU_add_test(pSuite, "case1", case1);
    CU_add_test(pSuite, "case2", case2);

    return FR_SUCC;
}
